package com.penghaisoft.microwms.base.web.data.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.penghaisoft.microwms.base.web.data.service.IMdModelService;
import com.penghaisoft.microwms.base.web.model.dao.MdModelMapper;
import com.penghaisoft.microwms.common.data.model.MdModel;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.BaseService;

/**
 * @Description 产品型号
 * @author luoteng
 * @date 2018年5月29日 下午2:31:24
 * @version 1.0
 */
@Service("mdModelService")
public class MdModelServiceImpl extends BaseService implements IMdModelService {
	@Resource
	private MdModelMapper mdModelMapper;

	/**
	 * 新增记录
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp create(MdModel mdModel) {
		mdModelMapper.create(mdModel);
		return success();
	}

	/**
	 * 删除记录（逻辑删除）
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp delete(MdModel mdModel) {
		mdModelMapper.delete(mdModel);
		return success();
	}
	
	@Override
	public Resp deleteErp(MdModel mdModel) {
		mdModelMapper.deleteErp(mdModel);
		return success();
	}

	/**
	 * 查询列表
	 * 
	 * @param pager
	 * @param baseResource
	 * @return
	 */
	@Override
	public Pager<MdModel> findListByCondition(int page, int rows,
			MdModel condition) {
		Pager<MdModel> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		condition.preQuery();
		List<MdModel> records = mdModelMapper.queryList(pager, condition);
		long size = mdModelMapper.queryCount(condition);
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}
	
	/**
	 * 查询单条
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public MdModel findById(String id) {
		return mdModelMapper.queryById(id);
	}

	/**
	 * 修改记录
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp update(MdModel mdModel) {
		mdModelMapper.updateBySelect(mdModel);
		return success();
	}
	
	/**
	 * 修改记录
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp updateErp(MdModel mdModel) {
		mdModelMapper.updateByModel(mdModel);
		return success();
	}
	
	@Override
	public List<MdModel> findList(MdModel condition){
		return mdModelMapper.queryByAny(condition);
	}

}
